package com.suntront.module_datasynch.taskdown

import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import com.alibaba.android.arouter.facade.annotation.Route
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleViewModel
import com.mtjsoft.www.kotlinmvputils.base.BaseRecycleviewActivity
import com.mtjsoft.www.kotlinmvputils.constants.RouterConstants
import com.suntront.module_datasynch.R
import com.suntront.module_datasynch.adapter.TaskDownAdapter
import com.suntront.module_datasynch.model.TaskDownModel

/**
 * 下载数据
 * @author mtj
 * @Package com.suntront.module_datasynch.taskdown
 * @date 2020-05-26 10:28:33
 */
@Route(path = RouterConstants.DataAsynch_Download)
class TaskDownRecycleViewActivity : BaseRecycleviewActivity<TaskDownModel, TaskDownViewModel>() {

    override fun providerVMClass(): Class<TaskDownViewModel>? {
        return TaskDownViewModel::class.java
    }

    override fun loadActivityInfo() {
        setPageTitle("下载册本")
        viewModel.refresh.value = false
        viewModel.load_more.value = false
        // 添加搜索按钮
        val searchView = View.inflate(getContext(), R.layout.include_top_search, null)
        val etcontent = searchView.findViewById<EditText>(R.id.mdetail_etcontent)
        etcontent.setText(viewModel.keyword)
        viewModel.setKeyWord(etcontent)
        val btnsearch = searchView.findViewById<TextView>(R.id.mdetail_btnsearch)
        btnsearch.setOnClickListener(this)
        getBaseTopLayout().addView(searchView)
        // 添加下载按钮
        val downView = View.inflate(getContext(), R.layout.include_download_btu, null)
        val btndownload = downView.findViewById<Button>(R.id.btu_download)
        btndownload.setOnClickListener(this)
        getBaseBottomLayout().addView(downView)
    }

    override fun setItemDecoration(): Int {
        return 0
    }

    override fun setPageSize(): Int {
        return Int.MAX_VALUE
    }

    override fun setLayoutManagerType(): BaseRecycleViewModel.LayoutManager {
        return BaseRecycleViewModel.LayoutManager.LinearLayoutManager
    }

    override fun setCount(): Int {
        return 2
    }

    override fun instanceAdapter(list: MutableList<TaskDownModel>): BaseQuickAdapter<TaskDownModel, BaseViewHolder> {
        return TaskDownAdapter(getContext(), list, this)
    }

    override fun onClick(p0: View) {
        super.onClick(p0)
        when (p0.id) {
            R.id.mdetail_btnsearch -> {
                viewModel.search()
            }
            R.id.btu_download -> {
                viewModel.download()
            }
        }
    }

    override fun onItemClick(position: Int, view: View) {
        super.onItemClick(position, view)
    }
}